package com.tiancheng.trade.settlement.controller.admin;

import com.tiancheng.trade.commom.core.data.Result;
import com.tiancheng.trade.settlement.exception.BusinessException;
import com.tiancheng.trade.settlement.service.settlement.ICouponsReportService;
import com.tiancheng.trade.settlement.vo.settlement.admin.CouponsReportVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import java.io.IOException;

/**
 * 优惠券报表
 *
 * @author dell
 */
@RestController
@RequestMapping("/admin/coupon/bill")
public class CouponsReportController {
    @Autowired
    ICouponsReportService service;

    @GetMapping("/query")
    public Result query(CouponsReportVO vo) throws BusinessException {
        return Result.success(service.query(vo));
    }

    @PostMapping("/update")
    public Result update(@RequestBody @Valid CouponsReportVO vo) throws BusinessException {
        return Result.success(service.update(vo));
    }

    /**
     * 优惠券报表导出
     *
     * @param vo
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @PostMapping("/export")
    public Result export(@RequestBody CouponsReportVO vo, HttpServletRequest request, HttpServletResponse response) throws IOException {
        service.export(vo.getYearMonth(), request, response);
        return Result.success("导出成功");
    }
}
